import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () => import('../views/home/HomeView.vue')
const Category = () => import('../views/category/CategoryView.vue')
const Cart = () => import('../views/cart/CartView.vue')
const Profile = () => import('../views/profile/ProfileView.vue')

//1.安装插件
Vue.use(VueRouter)

//2.创建路由对象
const routes = [
  {
    path: '',
    redirect: '/home',
  },
  {
    path: '/home',
    component: Home,
  },
  {
    path: '/category',
    component: Category,
  },
  {
    path: '/cart',
    component: Cart,
  },
  {
    path: '/profile',
    component: Profile,
  },
]
const router = new VueRouter({
  routes,
  mode: 'history',
})

router.beforeEach((to, from, next) => {
  console.log(to)
  // document.title = to.meta.title;
  document.title = to.matched[0].meta.title
  next()
})

//3.导出router
export default router
